package com.sanjiahantang.youjiarole.module.me.order.adapters;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.adapter.listview.BaseAdapterHelper;
import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.uilibrary.utils.Utils;
import com.sanjiahantang.uilibrary.views.TagGroup;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.config.SPConfig;
import com.sanjiahantang.youjiarole.config.StaticValue;
import com.sanjiahantang.youjiarole.module.common.beans.CartGoodsBean;
import com.sanjiahantang.youjiarole.module.goods.views.impl.GoodsDetailActivity;
import com.sanjiahantang.youjiarole.module.goods.views.impl.ReduceMoneyActivity;
import com.sanjiahantang.youjiarole.module.invoice.views.InvoiceView;
import com.sanjiahantang.youjiarole.module.invoice.views.impl.InvoiceActivity;
import com.sanjiahantang.youjiarole.module.me.address.beans.AddressBean;
import com.sanjiahantang.youjiarole.module.me.address.views.AddressView;
import com.sanjiahantang.youjiarole.module.me.address.views.impl.AddressListActivity;
import com.sanjiahantang.youjiarole.module.me.order.beans.CreateOrderPost;
import com.sanjiahantang.youjiarole.module.me.order.beans.OrderBean;
import com.sanjiahantang.youjiarole.module.me.order.beans.ShopListBean;
import com.sanjiahantang.youjiarole.module.me.order.presenters.OrderPresenter;
import com.sanjiahantang.youjiarole.module.me.order.views.OrderView;
import com.sanjiahantang.youjiarole.module.me.order.views.impl.LogisticsActivity;
import com.sanjiahantang.youjiarole.utils.FileUtils;
import com.sanjiahantang.youjiarole.utils.SPUtils;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by zy on 2017/9/27.
 */

public class OrderAdapter extends RecyclerView.Adapter implements StaticValue{

    private Context context;
    private LayoutInflater inflater;
    private OrderBean.Data data;
    private Picasso picasso;
    private String consumerMessage;
    private ArrayList<Integer> typeList;
    private ShopListBean.Data orderInfo;
    private OrderPresenter presenter;

    public OrderAdapter(Context context, ArrayList<Integer> typeList) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.picasso = Picasso.with(context);
        this.typeList = typeList;
    }

    public OrderBean.Data getData() {
        return data;
    }

    public void setData(OrderBean.Data data, ArrayList<Integer> typeList, ShopListBean.Data orderInfo, OrderPresenter presenter) {
        this.data = data;
        this.typeList.clear();
        this.typeList.addAll(typeList);
        this.orderInfo = orderInfo;
        this.presenter = presenter;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        int resId = -1;
        switch (viewType){
            case ORDER_PAGE_HOLDER_TYPE_ADDRESS:resId = R.layout.item_order_address;break;
            case ORDER_PAGE_HOLDER_TYPE_GOODS_LIST:resId = R.layout.item_me_order;break;
            case ORDER_PAGE_HOLDER_TYPE_GHT:resId = R.layout.item_ght;break;
            case ORDER_PAGE_HOLDER_TYPE_INVOICE:resId = R.layout.item_invoice;break;
            case ORDER_PAGE_HOLDER_TYPE_CONSUMER_MESSAGE:resId = R.layout.item_consumer_message;break;
            case ORDER_PAGE_HOLDER_TYPE_STATE:resId = R.layout.item_order_state;break;
        }
        return new OrderHolder(inflater.inflate(resId,null),data,viewType);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((OrderHolder)holder).bindData(data,typeList.get(position));
    }

    @Override
    public int getItemViewType(int position) {
        return typeList.get(position);
    }

    @Override
    public int getItemCount() {
        return typeList.size();
    }

    public CreateOrderPost getCreateOrderPost() {
        CreateOrderPost post = new CreateOrderPost();
        CreateOrderPost.OrderInvoiceInfoDtoBean orderInvoiceInfoDto = new CreateOrderPost.OrderInvoiceInfoDtoBean();
        List<CreateOrderPost.ShoppingCartInfoDtosBean> infoDtoBeanList = new ArrayList<>();
        post.setBuyPersonMessage(consumerMessage == null ? "" : consumerMessage);
        post.setPhone(SPUtils.get(context, SPConfig.PHONE,"").toString());
        post.setToken(ConfigValue.DATA_KEY);
        post.setPhoneTypeId(1);
        if (data.getAddress() != null){
            post.setUserAddressId(data.getAddress().getUcaId());
        }
        if (data.getInvoice() != null){
            orderInvoiceInfoDto.setInvoiceTitle(data.getInvoice().getInvoiceTitle());
            if (!TextUtils.isEmpty(data.getInvoice().getTaxNum())){
                orderInvoiceInfoDto.setIsPersonalOrCompany("1");
                orderInvoiceInfoDto.setTaxNum(data.getInvoice().getTaxNum());
            }else {
                orderInvoiceInfoDto.setIsPersonalOrCompany("0");
            }
        }else {
            orderInvoiceInfoDto.setInvoiceTitle("");
            orderInvoiceInfoDto.setIsPersonalOrCompany("0");
        }
        post.setOrderInvoiceInfoDto(orderInvoiceInfoDto);

        for (int i = 0,max = data.getGoods().size(); i < max;i++){
            CartGoodsBean.Data goods = data.getGoods().get(i);
            CreateOrderPost.ShoppingCartInfoDtosBean item = new CreateOrderPost.ShoppingCartInfoDtosBean();
            item.setGoodsName(goods.getGoodsName());
            item.setMgiId(goods.getMgiId());
            item.setMgpiValue(goods.getMgpiValue());
            item.setMgsciId(goods.getMgsciId());
            item.setNumber(goods.getNumber());
            item.setPrice(String.format("%.2f", Utils.toFloat(goods.getBasePrice())));
            item.setSkuId(goods.getSkuId());
            item.setSupplyId(goods.getSupplyId());
            item.setSupplyName(goods.getSupplyName());
            infoDtoBeanList.add(item);
        }
        post.setIsShoppingCartOrder(data.getIsShoppingCartOrder());
        post.setShoppingCartInfoDtos(infoDtoBeanList);
        return post;
    }

    public void setInvoice(String title, String taxNo) {

        CreateOrderPost.OrderInvoiceInfoDtoBean invoice = new CreateOrderPost.OrderInvoiceInfoDtoBean();
        invoice.setInvoiceTitle(title);
        invoice.setTaxNum(taxNo);
        data.setInvoice(invoice);
        notifyDataSetChanged();
    }

    public void setAddress(AddressBean.Data address) {
        data.setAddress(address);
        notifyDataSetChanged();
    }

    private class OrderHolder extends RecyclerView.ViewHolder{

        public OrderHolder(View itemView, OrderBean.Data data, int position) {
            super(itemView);
            bindData(data,position);
        }

        private void bindData(OrderBean.Data data, int position) {
            if(position == ORDER_PAGE_HOLDER_TYPE_ADDRESS){
                //地址
                bindAddress(itemView,data.getAddress());
            }

            if(position == ORDER_PAGE_HOLDER_TYPE_GOODS_LIST){
                //商品列表
                bindGoodsList(itemView,data.getGoods());
            }

            if (position == ORDER_PAGE_HOLDER_TYPE_GHT) {
                //高汇通
                bindGHT(itemView, data.getJdOrderInfo(),data.getmOrderInfo());
            }

            if(position == ORDER_PAGE_HOLDER_TYPE_INVOICE){
                //发票信息
                bindInvoice(itemView,data.getInvoice());
            }

            if (position == ORDER_PAGE_HOLDER_TYPE_CONSUMER_MESSAGE){
                //买家留言
                bindConsumerMessage(itemView,data.getConsumerMessage());
            }

            if (position == ORDER_PAGE_HOLDER_TYPE_STATE){
                //订单状态
                bindState(itemView);
            }
        }

        private void bindState(View itemView) {
            String stateName = orderInfo.getStatusName();
            if (orderInfo != null){
                int ivRes = -1;
                switch (orderInfo.getStatusId()){
                    case OrderView.TYPE_UN_PAY:
                        stateName = "待付款";
                        ivRes = R.drawable.i_unpay_head;
                        break;
                    case OrderView.TYPE_PART_PAY:
                        ivRes = R.drawable.i_unpay_head;
                        break;
                    case OrderView.TYPE_PAYED:
                        ivRes = R.drawable.i_payed_head;
                        break;
                    case OrderView.TYPE_COMPLETE:
                        stateName = "已完成";
                        ivRes = R.drawable.i_payed_head;
                        break;
                    case OrderView.TYPE_CLOSE:
                        ivRes = R.drawable.i_payed_head;
                        break;
                    case OrderView.TYPE_EVALUATED:
                        stateName = "已完成";
                        ivRes = R.drawable.i_payed_head;
                        break;
                }
                TextView txtState = (TextView) itemView.findViewById(R.id.txtState);
                ImageView ivState = (ImageView) itemView.findViewById(R.id.ivState);
                txtState.setText(stateName);
                ivState.setImageResource(ivRes);
            }

        }


        private void bindAddress(View itemView, AddressBean.Data data){
            if(data == null){
                //添加收货地址
                itemView.findViewById(R.id.rlAddAddress).setVisibility(View.VISIBLE);
                if (orderInfo == null || orderInfo.getOrderCode() == null){
                    itemView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            context.startActivity(new Intent(context, AddressListActivity.class));
                        }
                    });
                }

                itemView.findViewById(R.id.rlChangeAddress).setVisibility(View.GONE);

            }else{
                //赋值
                itemView.findViewById(R.id.rlAddAddress).setVisibility(View.GONE);
                itemView.findViewById(R.id.rlChangeAddress).setVisibility(View.VISIBLE);
                TextView txtReceiverName = (TextView) itemView.findViewById(R.id.txtReceiverName);
                TextView txtAddress = (TextView) itemView.findViewById(R.id.txtAddress);
                TextView txtPhone = (TextView) itemView.findViewById(R.id.txtPhone);

                txtReceiverName.setText(data.getCustomerName());
                txtAddress.setText(data.getFullAddress());
                txtPhone.setText(data.getCellPhone());

            }


            if (orderInfo == null || orderInfo.getStatusId() == OrderView.TYPE_UN_PAY){
                itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Activity activity = (Activity) context;
                        Intent intent = new Intent(context, AddressListActivity.class);
                        intent.putExtra(AddressView.KEY_ORDER,true);
                        activity.startActivityForResult(intent, OrderView.INTENT_ADDRESS);
                    }
                });
            }

        }

        private void bindGoodsList(View itemView, final List<CartGoodsBean.Data> goods) {

            itemView.findViewById(R.id.view_Line).setVisibility(View.GONE);
            ListView goodListView = (ListView) itemView.findViewById(R.id.goodListView);
            TextView txtGoodsCount = (TextView) itemView.findViewById(R.id.txtGoodsCount);
            TextView txtAmount = (TextView) itemView.findViewById(R.id.txtAmount);
            TextView txtRemain = (TextView) itemView.findViewById(R.id.txtRemain);
            itemView.findViewById(R.id.llAction).setVisibility(View.GONE);
            txtRemain.setVisibility(View.GONE);
            if (!TextUtils.isEmpty(data.getRemain())){
                txtRemain.setVisibility(View.VISIBLE);
                txtRemain.setText(data.getRemain());
            }

            if (orderInfo == null || orderInfo.getOrderCode() == null){
                itemView.findViewById(R.id.rlStatus).setVisibility(View.GONE);
                int count = 0;
                float price = 0f;
                for(CartGoodsBean.Data item : goods){
                    count += item.getNumber();
                    price += Float.parseFloat(item.getBasePrice()) * item.getNumber();
                }
                txtAmount.setText(String.format("%.2f",price));
                txtGoodsCount.setText(String.valueOf(count));
            }else{
                itemView.findViewById(R.id.rlStatus).setVisibility(View.VISIBLE);
                TextView txtOrderNum = (TextView) itemView.findViewById(R.id.txtOrderNum);
                txtOrderNum.setText(orderInfo.getOrderCode());
                TextView txtCreateTime = (TextView) itemView.findViewById(R.id.txtCreateTime);

                if (orderInfo.getCreateTime() != null){
                    txtCreateTime.setText(orderInfo.getCreateTime().substring(0,"yyyy-MM-dd".length()));
                }

                txtAmount.setText(String.format("%.2f",orderInfo.getPayMoney()));
                txtGoodsCount.setText(String.valueOf(goods.size()));
            }

            goodListView.setAdapter(new QuickAdapter<CartGoodsBean.Data>(context,R.layout.item_order_goods,goods) {
                @Override
                protected void convert(BaseAdapterHelper helper, final CartGoodsBean.Data item) {
                    helper.setText(R.id.txtTitle,item.getGoodsName());
                    helper.setText(R.id.txtPrice,String.format("%.2f",Utils.toFloat(item.getBasePrice())));
                    helper.setText(R.id.txtNumber,String.valueOf(item.getNumber()));
                    picasso.load(FileUtils.rePath(item.getUrl())).placeholder(RES_ID_GOODS_DEFAULT).into((ImageView) helper.getView(R.id.imgGoods));
                    helper.setOnClickListener(R.id.ll_ogitem, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Intent intent = new Intent(context, GoodsDetailActivity.class);
                            intent.putExtra("goodsId", item.getMgiId());
                            context.startActivity(intent);
                        }
                    });

                    TagGroup tgScale = helper.getView(R.id.tgScale);
                    tgScale.setTags(item.getMgpiValue());
                    if (orderInfo != null){
                        //已付款显示确认收货、申请退款按钮
                        helper.setVisible(R.id.panelAction,true);
                        final ShopListBean.Data.GoodsInfoDtoListBean bean = orderInfo.getGoodsInfoDtoList().get(helper.getPosition());
                        TextView btnTakeOver = helper.getView(R.id.btnTakeOver);
                        TextView btnRejected = helper.getView(R.id.btnRejected);
                        TextView btnLogistics = helper.getView(R.id.btnLogistics);
                        btnLogistics.setBackgroundResource(R.drawable.x_shape_green_order);




                        if ("1".equals(bean.getSupplyStateId())){

                            if (bean.getExpressCode() != null && bean.getExpressNumber() != null) {
                                btnLogistics.setVisibility(View.VISIBLE);
                                btnLogistics.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        context.startActivity(new Intent(context, LogisticsActivity.class)
                                                .putExtra("expressCode", bean.getExpressCode())
                                                .putExtra("expressNumber", bean.getExpressNumber())
                                                .putExtra("address",OrderAdapter.this.data.getAddress().getFullAddress())
                                        );
                                    }
                                });
                            } else {
                                btnLogistics.setVisibility(View.GONE);
                                btnLogistics.setOnClickListener(null);
                            }

                            if (bean.getExpressCode() != null && bean.getExpressNumber() != null) {
                                btnLogistics.setVisibility(View.VISIBLE);
                                btnLogistics.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        context.startActivity(new Intent(context, LogisticsActivity.class)
                                                .putExtra("expressCode", bean.getExpressCode())
                                                .putExtra("expressNumber", bean.getExpressNumber())
                                                .putExtra("address",OrderAdapter.this.data.getAddress().getFullAddress())
                                        );
                                    }
                                });
                            } else {
                                btnLogistics.setVisibility(View.GONE);
                                btnLogistics.setOnClickListener(null);
                            }

                            if (bean.getStatusId() == 4 || bean.getStatusId() == 6){
                                btnTakeOver.setVisibility(View.GONE);
                                btnRejected.setVisibility(View.VISIBLE);
                                btnRejected.setText(bean.getStatusName());

                                btnRejected.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        context.startActivity(new Intent(context, ReduceMoneyActivity.class)
                                                .putExtra(KEY_PARAM,bean)
                                        );
                                    }
                                });
                            }else if(bean.getStatusId() == 8){

                                //收货
                                btnTakeOver.setVisibility(View.VISIBLE);
                                btnTakeOver.setText("确认收货");
                                btnTakeOver.setTextColor(COLOR_PRIMARY);
                                btnTakeOver.setBackgroundResource(R.drawable.x_shape_green_order);
                                btnTakeOver.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        presenter.operatorState(context,2,bean.getOrderRecordCode(),orderInfo.getOrderCode());
                                    }
                                });

                                //退款
                                btnRejected.setVisibility(View.VISIBLE);
                                btnRejected.setText("退款关闭");
                                btnRejected.setTextColor(Color.GRAY);
                                btnRejected.setBackgroundResource(R.drawable.x_shape_gray_border);

                                btnRejected.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        context.startActivity(new Intent(context, ReduceMoneyActivity.class)
                                                .putExtra(KEY_PARAM,bean)
                                        );
                                    }
                                });

                            }else if(bean.getStatusId() == 2){

                                //收货
                                btnTakeOver.setText("确认收货");
                                btnTakeOver.setTextColor(COLOR_PRIMARY);
                                btnTakeOver.setBackgroundResource(R.drawable.x_shape_green_order);
                                btnTakeOver.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        presenter.operatorState(context,0,bean.getOrderRecordCode(),orderInfo.getOrderCode());
                                    }
                                });

                                //退款
                                btnRejected.setText("申请退款");
                                btnRejected.setTextColor(Color.GRAY);
                                btnRejected.setBackgroundResource(R.drawable.x_shape_gray_border);
                                btnRejected.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        presenter.operatorState(context,1,bean.getOrderRecordCode(),orderInfo.getOrderCode());
                                    }
                                });
                            }else if(bean.getStatusId() == 10){//退款关闭已收货

                                //收货
                                btnTakeOver.setText("已收货");
                                btnTakeOver.setTextColor(Color.GRAY);
                                btnTakeOver.setOnClickListener(null);
                                //退款
                                btnRejected.setVisibility(View.VISIBLE);
                                btnRejected.setText("退款关闭");
                                btnRejected.setTextColor(Color.GRAY);
                                btnRejected.setBackgroundResource(R.drawable.x_shape_gray_border);

                                btnRejected.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        context.startActivity(new Intent(context, ReduceMoneyActivity.class)
                                                .putExtra(KEY_PARAM,bean)
                                        );
                                    }
                                });
                            }else if(bean.getStatusId() == 3 || bean.getStatusId() == 9){
                                //收货
                                btnTakeOver.setText("已收货");
                                btnTakeOver.setBackgroundColor(Color.TRANSPARENT);
                                btnTakeOver.setTextColor(Color.GRAY);
                                btnTakeOver.setOnClickListener(null);
                                btnTakeOver.setVisibility(View.VISIBLE);

                                //退款
                                btnRejected.setVisibility(View.GONE);
                                if (bean.getReduceMoney() != null){
                                    float reduceMoney = Float.valueOf(bean.getReduceMoney());
                                    if (reduceMoney > 0){
                                        //退款
                                        btnRejected.setVisibility(View.VISIBLE);
                                        btnRejected.setText("退款关闭");
                                        btnRejected.setTextColor(Color.GRAY);
                                        btnRejected.setBackgroundResource(R.drawable.x_shape_gray_border);

                                        btnRejected.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                context.startActivity(new Intent(context, ReduceMoneyActivity.class)
                                                        .putExtra(KEY_PARAM,bean)
                                                );
                                            }
                                        });
                                    }
                                }
                            }else{
                                btnRejected.setVisibility(View.GONE);
                                btnTakeOver.setVisibility(View.GONE);
                            }



                        }else{
                            helper.setVisible(R.id.panelAction,false);
                        }


                    }else{
                        helper.setVisible(R.id.panelAction,false);
                    }



                }
            });
        }

        private void bindGHT(View itemView, HashMap<String, String> jdOrderInfo, ArrayList<HashMap<String, String>> mOrderInfo) {
            final View llJDTitle = itemView.findViewById(R.id.llJDTitle);
            final View llZFTitle = itemView.findViewById(R.id.llZFTitle);
            final ImageView ivArrow = (ImageView) itemView.findViewById(R.id.ivArrow);
            if (jdOrderInfo != null && jdOrderInfo.containsKey("stageOrderId")){
                TextView txtJDTitle = (TextView) itemView.findViewById(R.id.txtJDTitle);
                txtJDTitle.setText(jdOrderInfo.get("stageOrderId"));
            }

            if (mOrderInfo != null){
                String str = "";
                for (int i = 0,max = mOrderInfo.size();i < max;i++){
                    if (mOrderInfo.get(i).containsKey("payOrderId")){
                        str += mOrderInfo.get(i).get("payOrderId");
                        str += "\n";
                    }
                }

                if (!TextUtils.isEmpty(str)){
                    str = str.substring(0,str.length() - 1);
                }

                TextView txtZFTitle = (TextView) itemView.findViewById(R.id.txtZFTitle);
                txtZFTitle.setText(str);

            }

            itemView.findViewById(R.id.rlTrade).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (llJDTitle.getVisibility() == View.VISIBLE){
                        llJDTitle.setVisibility(View.GONE);
                        llZFTitle.setVisibility(View.GONE);
                        ivArrow.setImageResource(R.drawable.i_down_gray);
                    }else{
                        llJDTitle.setVisibility(View.VISIBLE);
                        llZFTitle.setVisibility(View.VISIBLE);
                        ivArrow.setImageResource(R.drawable.i_up_green);
                    }
                }
            });
        }

        private void bindInvoice(View itemView, final CreateOrderPost.OrderInvoiceInfoDtoBean invoice) {
            if(invoice == null || invoice.getOiiId() == 0){
                itemView.findViewById(R.id.rlNoInvoice).setVisibility(View.VISIBLE);
                itemView.findViewById(R.id.rlInvoiceInfo).setVisibility(View.GONE);
            }else {
                itemView.findViewById(R.id.rlNoInvoice).setVisibility(View.GONE);
                itemView.findViewById(R.id.rlInvoiceInfo).setVisibility(View.VISIBLE);

                TextView txtInvoiceTitle = (TextView) itemView.findViewById(R.id.txtInvoiceTitle);
                TextView txtInvoiceTaxNo = (TextView) itemView.findViewById(R.id.txtInvoiceTaxNo);
                if (!TextUtils.isEmpty(invoice.getTaxNum())){
                    itemView.findViewById(R.id.llInvoiceTaxNo).setVisibility(View.VISIBLE);
                    txtInvoiceTaxNo.setText(invoice.getTaxNum());
                }else {
                    itemView.findViewById(R.id.llInvoiceTaxNo).setVisibility(View.GONE);
                }
                txtInvoiceTitle.setText(invoice.getInvoiceTitle());
            }

            if (orderInfo.getStatusId() == OrderView.TYPE_COMPLETE || orderInfo.getStatusId() == OrderView.TYPE_EVALUATED){
                itemView.setVisibility(View.VISIBLE);
                if (orderInfo != null && (orderInfo.getOrderInvoiceInfoDto() == null || orderInfo.getOrderInvoiceInfoDto().getOiiId() == 0)){
                    itemView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Activity activity = (Activity) context;
                            Intent mIntent = new Intent(activity, InvoiceActivity.class);
                            mIntent.putExtra("orderCode",orderInfo.getOrderCode());
                            float money = 0;
                            for (ShopListBean.Data.GoodsInfoDtoListBean item : orderInfo.getGoodsInfoDtoList()){
                                money += item.getResult();

                                if (item.getReduceMoney() != null){
                                    float reduceMoney = Float.valueOf(item.getReduceMoney());
                                    money -= reduceMoney;
                                    if (money < 0) money = 0;
                                }
                            }


                            mIntent.putExtra("money",money);
                            activity.startActivityForResult(mIntent, OrderView.INTENT_INVOICE);
                        }
                    });
                }else{
                    itemView.setOnClickListener(null);
                }
            }else{
                itemView.setVisibility(View.GONE);
            }

            final View llInvoiceTitle = itemView.findViewById(R.id.llInvoiceTitle);
            final View llInvoiceTaxNo = itemView.findViewById(R.id.llInvoiceTaxNo);
            final ImageView ivArrow = (ImageView) itemView.findViewById(R.id.ivArrow);
            itemView.findViewById(R.id.rlInvoiceInfo).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (llInvoiceTitle.getVisibility() == View.VISIBLE){
                        llInvoiceTitle.setVisibility(View.GONE);
                        llInvoiceTaxNo.setVisibility(View.GONE);
                        ivArrow.setImageResource(R.drawable.i_down_gray);
                    }else{
                        llInvoiceTitle.setVisibility(View.VISIBLE);
                        llInvoiceTaxNo.setVisibility(View.VISIBLE);
                        ivArrow.setImageResource(R.drawable.i_up_green);
                    }
                }
            });
        }

        private void bindConsumerMessage(View itemView, String message) {
            EditText etConsumerMessage = (EditText) itemView.findViewById(R.id.etConsumerMessage);
            if (!TextUtils.isEmpty(message)){
                etConsumerMessage.setText(message);
            }

            if (orderInfo != null && orderInfo.getStatusId() != OrderView.TYPE_UN_PAY){
                etConsumerMessage.setEnabled(false);
            }

            etConsumerMessage.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    consumerMessage = s.toString();
                }

                @Override
                public void afterTextChanged(Editable s) {

                }
            });
        }

    }



}
